package com.example.administrator.managesystem.view;


import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.example.administrator.managesystem.R;
import com.example.administrator.managesystem.activity.firstpage.circle.interfaces.OnItemCollectClickListener;
import com.example.administrator.managesystem.activity.firstpage.circle.interfaces.OnItemRepostClickListener;
import com.example.administrator.managesystem.activity.firstpage.circle.ui.SendCircleActivity;
import com.makeramen.roundedimageview.RoundedImageView;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/1/7.
 */
public class PickLandDialog extends Dialog {

    private Button button_cancel, button_send;//定义取消与确认按钮
    private EditText land_name;//定义标题文字
    private TextView land_tag,location_tv,tips;
    private RelativeLayout type_rl,layout_type;
    private RoundedImageView add_pic;
    private TagFlowLayout mFlowLayout;
    private LocationClient mLocationClient = null;    //LocationClient类是定位SDK的核心类

    //构造方法
    public PickLandDialog(Context context,boolean isShow,String name) {

        //设置对话框样式
        super(context, R.style.mdialog);
        //通过LayoutInflater获取布局
        final View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_pick_land, null);
        land_name = view.findViewById(R.id.land_name);   //获取显示标题的文本框控件
        land_tag = view.findViewById(R.id.land_type_tag);   //获取显示标题的文本框控件
        tips=view.findViewById(R.id.tips);
        location_tv=view.findViewById(R.id.location_land);
//        type_submit=view.findViewById(R.id.flowlayout_submit);
        type_rl=view.findViewById(R.id.choose_type_rl);
        layout_type=view.findViewById(R.id.layout_type);
        add_pic=view.findViewById(R.id.add_land_pic);
        mFlowLayout=view.findViewById(R.id.flowlayout);
        button_cancel = view.findViewById(R.id.btn_cancel);    //获取取消按钮
        button_send = view.findViewById(R.id.btn_send);  //获取确认退出按钮
        if(isShow){ tips.setVisibility(View.VISIBLE); }
            land_name.setText(name);

        //声明LocationClient类
       MyLocationListener myListener = new MyLocationListener();
        mLocationClient = new LocationClient(context);
        //注册监听函数
        mLocationClient.registerLocationListener(myListener);
        LocationClientOption option = new LocationClientOption();
        option.setIsNeedAddress(true);//是否要地址
        option.setOpenGps(true);
        option.setCoorType("gcj02"); // 设置坐标类型
        option.setScanSpan(1000);//可选，默认0，即仅定位一次，设置发起连续定位请求的间隔需要大于等于1000ms才是有效的
        option.setOpenAutoNotifyMode();
        mLocationClient.setLocOption(option);
        mLocationClient.start();
        setContentView(view);  //设置显示的视图

        layout_type.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                typeListener.onShowTypeClick(view,type_rl,mFlowLayout,land_tag);
            }
        });


        add_pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                picListener.onShowPicClick(view,add_pic);
            }
        });

        button_send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                enterListener.onEnterClick(view,land_name,location_tv);
            }
        });

    }

    //设置内容
    public String getName() {
        return land_name.getText().toString();
    }
    //设置内容
    public String getTag() {
        return land_tag .getText().toString();
    }
    //取消监听
    public void setOnCancelListener(View.OnClickListener listener) {
        button_cancel.setOnClickListener(listener);
    }

    //点击三角
    private OnEnterClickListener enterListener;
    public interface OnEnterClickListener {
        void onEnterClick( View view,EditText editText,TextView location);
    }
    public void setOnEnterClickListener (OnEnterClickListener listener) {
        enterListener=listener;
    }
    //点击三角
    private OnShowTypeClickListener typeListener;
    public interface OnShowTypeClickListener {
        void onShowTypeClick( View view,RelativeLayout type_rl, TagFlowLayout mFlowLayout,TextView land_tag);
    }
    public void setOnShowTypeClickListener (OnShowTypeClickListener listener) {
        typeListener=listener;
    }
//
//   //确定
//    private OnShowOkClickListener okListener;
//    public interface OnShowOkClickListener {
//        void onShowTypeClick( View view,String tag,RelativeLayout type_rl);
//    }
//    public void setOnShowOkClickListener (OnShowOkClickListener listener) {
//        okListener=listener;
//    }

    private OnShowPicClickListener picListener;
    public interface OnShowPicClickListener {
        void onShowPicClick( View view,ImageView imageView);
    }
    public void setOnShowPicClickListener (OnShowPicClickListener listener) {
        picListener=listener;
    }

    /***
     * 定位结果回调，在此方法中处理定位结果
     */
    public class MyLocationListener extends BDAbstractLocationListener {
        @Override
        public void onReceiveLocation(final BDLocation location) {
            //此处的BDLocation为定位结果信息类，通过它的各种get方法可获取定位相关的全部结果
            //以下只列举部分获取地址相关的结果信息
            //更多结果信息获取说明，请参照类参考中BDLocation类中的说明
            Log.e("msg","location.getProvince():"+location.getProvince());
            location_tv.setText(location.getProvince()+"-"+location.getCity()+"-"+location.getDistrict()+"-"+location.getStreet());


        }

    }

}
